<template>
    <div class="">
        <!-- 表格 -->
        <el-table :data="roleList" border style="width: 100%">
            <el-table-column label="角色编号" width="80" prop="id">
            </el-table-column>
            <el-table-column label="角色名称" width="150" prop="rolename">
            </el-table-column>
            <!-- <el-table-column label="所属角色" width="150" prop="address">
            </el-table-column> -->
            <el-table-column label="状态">
                <template slot-scope="item">
                    <div v-if="item.row.status == 1">
                        <el-button type="success" plain disabled>启用</el-button>
                    </div>
                    <div v-else>
                        <el-button type="danger" plain disabled>禁用</el-button>
                    </div>
                </template>

            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button size="mini" type="primary" icon="el-icon-edit"
                            @click="edit(item.row.id)">编辑</el-button>
                        <el-button size="mini" type="danger" icon="el-icon-delete"
                            @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>

            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex';
import { roleDel } from '../../request/api'
export default {
    data() {
        return {

        }
    },
    computed: {
        ...mapGetters({
            roleList: 'role/getRoleInfo'
        })
    },
    mounted() {
        this.getRoleAction()
    }
    ,
    methods: {
        edit(id) {
            this.$emit('edit',id)
        },
        ...mapActions({
            getRoleAction: 'role/getRoleAction'
        }),
        del(id) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                roleDel({ id }).then(res => {
                    if (res.code == 200) {
                        this.$message.success(res.msg)
                        this.getRoleAction()
                    }else{
                        this.$message.worry(res.msg)
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        }
    },
}
</script>
<style scoped>
.btnInfo {
    margin: 10px 5px;
}
</style>